{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d7245fe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ac5a0301",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的支付宝余额：123\n",
      "-------------[shopping-list]-------------\n",
      "商品编号：0, 商品名称：芝士莓莓, 商品价格：23 元\n",
      "商品编号：1, 商品名称：芝士葡萄, 商品价格：23 元\n",
      "商品编号：2, 商品名称：西瓜椰椰, 商品价格：22 元\n",
      "商品编号：3, 商品名称：鸭屎香柠檬茶, 商品价格：16 元\n",
      "商品编号：4, 商品名称：布蕾波霸奶茶, 商品价格：18 元\n",
      "请输入正确的商品编号：1\n",
      "【芝士葡萄】已经添加到您的购物车，您的余额还有【100】元\n",
      "-------------[shopping-list]-------------\n",
      "商品编号：0, 商品名称：芝士莓莓, 商品价格：23 元\n",
      "商品编号：1, 商品名称：芝士葡萄, 商品价格：23 元\n",
      "商品编号：2, 商品名称：西瓜椰椰, 商品价格：22 元\n",
      "商品编号：3, 商品名称：鸭屎香柠檬茶, 商品价格：16 元\n",
      "商品编号：4, 商品名称：布蕾波霸奶茶, 商品价格：18 元\n",
      "请输入正确的商品编号：q\n",
      "------------------\n",
      "您的购物车：[['芝士葡萄', 23]]\n",
      "您的余额还有：100元\n"
     ]
    }
   ],
   "source": [
    "# 商品列表\n",
    "goods_list = [\n",
    "    # 商品模板：[商品名称]\n",
    "    [\"芝士莓莓\", 23],\n",
    "    [\"芝士葡萄\", 23],\n",
    "    [\"西瓜椰椰\", 22],\n",
    "    [\"鸭屎香柠檬茶\", 16],\n",
    "    [\"布蕾波霸奶茶\", 18]\n",
    "]\n",
    "shopping_car = []\n",
    "# 用户输入：input\n",
    "Alipay = int(input(\"请输入您的支付宝余额：\"))\n",
    "\n",
    "# 打印商品列表（规范打印，样式是先写的，然后再输入数据）\n",
    "# 先设计模板的样式：商品编号：xx，商品名臣：xx，商品的价格：xx元\n",
    "while True:\n",
    "    print(\"-------------[shopping-list]-------------\")\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"商品编号：%s, 商品名称：%s, 商品价格：%s 元\"%(i, goods_list[i][0], goods_list[i][1]))\n",
    "\n",
    "    choice = input(\"请输入正确的商品编号：\")\n",
    "    if choice.isdigit():\n",
    "        # 如果用户输入的是数字，那就用int将数据类型转换为数值\n",
    "        choice = int(choice)\n",
    "        # 看看用户的余额够不够来购买商品\n",
    "        if choice < len(goods_list):\n",
    "            if Alipay < goods_list[choice][1]:   # 不够的话\n",
    "                print(\"你看看你的余额！你都没钱了！还买？！\")\n",
    "            else:   # 如果够！那就减去他的支付宝余额！\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                shopping_car.append(goods_list[choice])\n",
    "                print(\"【%s】已经添加到您的购物车，您的余额还有【%s】元\"%(goods_list[choice][0], Alipay))\n",
    "        else:\n",
    "            print(\"您想要的商品不存在，请输入正确的商品编号！\")\n",
    "    elif choice == \"q\":\n",
    "        print(\"------------------\")\n",
    "        print(\"您的购物车：%s\"%(shopping_car))\n",
    "        print(\"您的余额还有：%d元\"%(Alipay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入正确的商品编号！或按“q”退出购物！\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d93ca86",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81b70990",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
